import {createStore, applyMiddleware, Store, AnyAction, CombinedState, Dispatch} from 'redux';
import reducers from './reducers';
import logger from 'redux-logger';
import thunk, {ThunkDispatch, ThunkAction} from 'redux-thunk';
import promise from 'redux-promise';
import {routerMiddleware} from 'connected-react-router';
import history from './history';
let store: Store<CombinedState, AnyAction> = createStore<CombinedState, AnyAction, {}, {}>(reducers, applyMiddleware(thunk, routerMiddleware(history), promise, logger));
export default store;
import {persistStore, persistReducer} from 'redux-persist'
import storage from "redux-persist/lib/storage"

const persistConfig = {
    key: 'root',
    storage,
    whitelist:['cart']
}

const persistedReducer = persistReducer(persistConfig, reducers)
let store:Store<CombinedState, AnyAction> = createStore<
    CombinedState,
    AnyAction,
    {},
    {}
>(
    persistedReducer, 
    applyMiddleware(thunk, routerMiddleware(history), promise, logger)
)

let persistor = persistStore(store)

export type StoreGetState = () => CombinedState
export type StoreDispatch = Dispatch & ThunkDispatch<CombinedState, any, AnyAction>
export {store, persistor}